package controller.admin;

import service.OrderService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AdminOrderStatusServlet", value = "/admin/order_status")
public class AdminOrderStatusServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        OrderService os = new OrderService();
        String status = request.getParameter("status");
        String ordreId = request.getParameter("id");
        //参数不合法
        if (status != null && !"".equals(status) && ordreId != null && !"".equals(ordreId)) {
            boolean flag = os.updateStatus(Integer.parseInt(ordreId), Integer.parseInt(status));
        }
        String referer = request.getHeader("Referer");
        response.sendRedirect(referer);
    }
}
